/* Eshm - SHM abstraction
 * Copyright (C) 2008-2012 Jorge Luis Zapata
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "Eshm.h"
#include "eshm_private.h"
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
struct _Eshm_Segment
{
	Eshm_Segment_Descriptor *d;
	void *data;

	size_t size;
};
/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
Eshm_Segment * eshm_segment_new(Eshm_Segment_Descriptor *d, size_t size,
		void *data)
{
	Eshm_Segment *thiz;

	if (!d) return NULL;
	if (!d->free) return NULL;
	if (!d->map_get) return NULL;

	thiz = calloc(1, sizeof(Eshm_Segment));
	thiz->d = d;
	thiz->data = data;
	thiz->size = size;

	return thiz;
}

void * eshm_segment_data_get(Eshm_Segment *thiz)
{
	return thiz->data;
}
/*============================================================================*
 *                                   API                                      *
 *============================================================================*/

/**
 * Deletes a segment.
 * @param thiz The segment to delete
 */
EAPI void eshm_segment_delete(Eshm_Segment *thiz)
{
	if (!thiz) return;
	thiz->d->free(thiz->data);
	free(thiz);
}

/**
 * Gets the memory pointer associated with this segment
 * @param thiz The segment to get the data from
 * @return The memory pointer
 */
EAPI void * eshm_segment_map_get(Eshm_Segment *thiz)
{
	if (!thiz) return NULL;
	return thiz->d->map_get(thiz->data);
}

/**
 * Gets the size of a segment
 * @param thiz The segment to get the size from
 * @return The size of the sement
 */
EAPI size_t eshm_segment_size_get(Eshm_Segment *thiz)
{
	return thiz->size;
}

#if 0
/**
 * Locks the segment for read or write
 */
EAPI Eina_Bool eshm_segment_lock(Eshm_Segment *thiz, Eina_Bool write)
{

}

/**
 *  Unlocks the segment for read or write
 */
EAPI void eshm_segment_unlock(Eshm_Segment *thiz)
{

}
#endif


